package com.wuyan.locationdog.viewmodel

import androidx.lifecycle.MutableLiveData
import com.arcsoft.commonbase.base.BaseViewModel
import com.arcsoft.commonbase.bean.MsgBean
import com.arcsoft.commonbase.bean.MsgCalendarBean
import com.arcsoft.commonbase.bean.MsgDetail
import com.arcsoft.commonbase.bean.MsgUnReadCountBean
import com.arcsoft.commonbase.ext.customShowLong
import com.arcsoft.commonbase.net.RetrofitManager
import com.blankj.utilcode.util.ToastUtils

class MsgViewModel : BaseViewModel() {


    val anyBean = MutableLiveData<Any>()

    val msgDetail = MutableLiveData<MsgDetail>()


    val msgCalendarBean = MutableLiveData<MsgCalendarBean>()
    val msgBean = MutableLiveData<MsgBean>()


    val msgUnReadCountBean = MutableLiveData<MsgUnReadCountBean>()


    fun msgList(map: HashMap<String, Any>) {
        launch(block = {
            msgBean.value = RetrofitManager.apiService.msgList(map).apiData()
        })
    }

    fun msgDeviceList(map: HashMap<String, Any>) {
        launch(block = {
            msgBean.value = RetrofitManager.apiService.msgDeviceList(map).apiData()
        })
    }

    fun msgDetail(map: HashMap<String, Any>) {
        launch(block = {
            msgDetail.value = RetrofitManager.apiService.msgDetail(map).apiData()
        })
    }

    fun msgCalendar(map: HashMap<String, Any>) {
        launch(block = {
            msgCalendarBean.value = RetrofitManager.apiService.msgCalendar(map).apiData()
        })
    }

    fun msgReadAll(map: HashMap<String, Any>, showToast: Boolean = true) {
        launch(block = {

            if (showToast) {
                anyBean.value = RetrofitManager.apiService.msgReadAll(map).apiData()
                customShowLong("消息已读")
            } else {
                RetrofitManager.apiService.msgReadAll(map).apiData()
            }
        })
    }

    fun deleteMsg(map: MutableList<String>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.deleteMsg(map).apiData()
            customShowLong("删除成功")

        })
    }

    fun msgUnreadCount(map: HashMap<String, Any>) {
        launch(block = {
            msgUnReadCountBean.value = RetrofitManager.apiService.msgUnreadCount(map).apiData()
        })
    }

    fun shareAccept(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.shareAccept(map).apiData()
            customShowLong("成功")

        })
    }

    fun teamAccept(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.teamAccept(map).apiData()
        })
    }
    fun getMsgShareTeamPerson(map: HashMap<String, Any> ,onSuccess: (Any) -> Unit) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.getMsgShareTeamPerson(map).apiData()
        })
    }
    fun msgRead(map: MutableList<String>) {
        launch(block = {
            RetrofitManager.apiService.msgRead(map).apiData()
        })
    }


}